//
//  RequestManager.m
//  HuiPinzhijia
//
//  Created by LLMPro on 16/8/30.
//  Copyright © 2016年 LLMPro. All rights reserved.
//

#import "RequestManager.h"
#import "HttpService.h"
#define BaseUrl @"http://e.hulianwangdai.com/mobile.php"
@interface RequestManager (){
    
    NSDictionary * _requestUrl;
    
}

@end

@implementation RequestManager

+ (RequestManager *)sharedManager{
    
    static RequestManager * reqestManager = nil;
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        reqestManager = [[RequestManager alloc] init];
        
    });
    
    reqestManager.login=@"MyGoods";
    
    reqestManager.homeGoods = @"MyGoods";
    
    reqestManager.goodsDetails = @"MyGoods";
    
    reqestManager.HomeAdPositionId = @"Lee";
    
    reqestManager.homeIMG = @"Lee";
    
    return reqestManager;
    
}

//广告页
- (void)setHomeAdPositionId:(NSString *)HomeAdPositionId {
    NSString * str=[NSString stringWithFormat:@"%s",__func__];
    _HomeAdPositionId=[str substringWithRange:NSMakeRange(20,str.length-22)];
}

- (void)setHomeIMG:(NSString *)homeIMG{
    NSString * str=[NSString stringWithFormat:@"%s",__func__];
    _homeIMG=[str substringWithRange:NSMakeRange(20,str.length-22)];
}




- (void)initUrl{
    
    if (!_requestUrl) {
        
        _requestUrl = @{@"HomeGoods":[NSString stringWithFormat:@"%@/Index/best",BaseUrl],
                        
                        @"GoodsDetails":[NSString stringWithFormat:@"%@/Goods/info",BaseUrl],
                        
                        @"Login":[NSString stringWithFormat:@"%@/Public/checkLogin",BaseUrl],
                       /*
                        首页广告位
                       */
                        @"HomeAdPositionId":[NSString stringWithFormat:@"%@/Index/getAD",BaseUrl],
                        
                        //轮播视图
                        @"HomeIMG":[NSString stringWithFormat:@"%@/Index/slide",BaseUrl]

                        
                        };
        
        
        
    }

}
-(void)getParameters:(NSDictionary *) parameters type:(NSString *)type success:(void (^)(id)) success_block failure:(void (^)(id)) failure_blcok{
    
    [self initUrl];
    
    if ([HttpService checkNetworkStatus]) {
        
        NSString * url = _requestUrl[type];
        
        if(url == nil){
            
            NSError *error = [[NSError alloc]initWithDomain:@"url为空！" code:9999 userInfo:nil];
            
            failure_blcok(error);
            
        }
        
        [HttpService getRequest:url params:parameters success:success_block failure:failure_blcok];
        
    }
    
    
}

-(void)postParameters:(NSDictionary *) parameters type:(NSString *)type success:(void (^)(id)) success_block failure:(void (^)(id)) failure_blcok{





}


@end
